package com.briup.sms.web.handler;

import com.briup.sms.utils.Result;
import com.briup.sms.utils.ResultCode;
import com.briup.sms.utils.SMSException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        if (e instanceof SMSException){
            SMSException smsException= (SMSException) e;
            return  Result.error(smsException.getResultCode());
        }else {
            return  Result.error(ResultCode.SYSTEM_INNER_ERROR);
        }
    }
}
